﻿using SD.Common;
using SD.Toolkits.Mapper;
using SlamDunk.MES.IAppService.DTOs.Outputs.ExecutionContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.MaintenanceContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.PlanContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.QualityContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.StockContext;
using SlamDunk.MES.Presentation.Models.ReportModels;

namespace SlamDunk.MES.Presentation.Maps
{
    /// <summary>
    /// 报表模型相关映射
    /// </summary>
    public static class ReportMap
    {
        #region # 销售订单映射 —— static SaleOrderRp ToReportView(this SaleOrderInfo saleOrderInfo)
        /// <summary>
        /// 销售订单映射
        /// </summary>
        public static SaleOrderRp ToReportView(this SaleOrderInfo saleOrderInfo)
        {
            SaleOrderRp saleOrderRp = saleOrderInfo.Map<SaleOrderInfo, SaleOrderRp>();
            saleOrderRp.SaleOrderNo = saleOrderInfo.Number;
            saleOrderRp.CustomerName = saleOrderInfo.CustomerInfo.Name;

            return saleOrderRp;
        }
        #endregion

        #region # 销售订单明细映射 —— static SaleOrderDetailRp ToReportView(this SaleOrderDetailInfo...
        /// <summary>
        /// 销售订单明细映射
        /// </summary>
        public static SaleOrderDetailRp ToReportView(this SaleOrderDetailInfo detailInfo)
        {
            SaleOrderDetailRp detailRp = detailInfo.Map<SaleOrderDetailInfo, SaleOrderDetailRp>();
            detailRp.ProductNo = detailInfo.ProductInfo.Number;
            detailRp.ProductName = detailInfo.ProductInfo.Name;
            detailRp.Unit = detailInfo.ProductInfo.StandardUnitNo;

            return detailRp;
        }
        #endregion

        #region # 入库单映射 —— static StockInOrderRp ToReportView(this StockInOrderInfo stockInOrderInfo)
        /// <summary>
        /// 入库单映射
        /// </summary>
        public static StockInOrderRp ToReportView(this StockInOrderInfo stockInOrderInfo)
        {
            StockInOrderRp stockInOrderRp = stockInOrderInfo.Map<StockInOrderInfo, StockInOrderRp>();
            if (stockInOrderInfo?.SourceOrderType != null)
            {
                stockInOrderRp.SourceOrderType = EnumExtension.GetEnumMember(stockInOrderInfo?.SourceOrderType);
            }
            return stockInOrderRp;
        }
        #endregion

        #region # 入库/出库单明细映射 —— static StockOrderDetailRp ToReportView(this SaleOrderDetailInfo...
        /// <summary>
        /// 入库/出库单明细映射
        /// </summary>
        public static StockOrderDetailRp ToReportView(this StockOrderDetailInfo detailInfo)
        {
            StockOrderDetailRp detailRp = detailInfo.Map<StockOrderDetailInfo, StockOrderDetailRp>();
            detailRp.MaterialNo = detailInfo.MaterialInfo.Number;
            detailRp.MaterialName = detailInfo.MaterialInfo.Name;
            detailRp.StandardUnitNo = detailInfo.MaterialInfo.StandardUnitNo;
            detailRp.SupplierNo = detailInfo.MaterialLotInfo?.SupplierNo;
            detailRp.SupplierName = detailInfo.MaterialLotInfo?.SupplierName;
            detailRp.ProductionBatchNo = detailInfo.MaterialLotInfo?.ProductionBatchNo;
            detailRp.ProducedDate = detailInfo.MaterialLotInfo?.ProducedDate;
            detailRp.GuaranteePeriod = detailInfo.MaterialLotInfo?.GuaranteePeriod.Days;
            detailRp.ExpiredDate = detailInfo.MaterialLotInfo?.ExpiredDate;
            detailRp.ReceptionDate = detailInfo.MaterialLotInfo?.ReceptionDate;
            detailRp.Specification = detailInfo.MaterialLotInfo?.Specification;
            detailRp.InitialQuantity = detailInfo.MaterialLotInfo?.InitialQuantity;
            if (detailInfo.MaterialLotInfo?.MaterialSourceType != null)
            {
                detailRp.MaterialSourceType = EnumExtension.GetEnumMember(detailInfo.MaterialLotInfo?.MaterialSourceType);
            }
            detailRp.FacilityName = detailInfo.MaterialLotInfo?.FacilityInfo?.Name;
            detailRp.MaterialDescription = detailInfo.MaterialLotInfo?.Description;
            return detailRp;
        }
        #endregion

        #region # 出库单映射 —— static ToReportView ToReportView(this StockOutOrderInfo stockOutOrderInfo)
        /// <summary>
        /// 出库单映射
        /// </summary>
        public static StockOutOrderRp ToReportView(this StockOutOrderInfo stockOutOrderInfo)
        {
            StockOutOrderRp stockInOrderRp = stockOutOrderInfo.Map<StockOutOrderInfo, StockOutOrderRp>();
            return stockInOrderRp;
        }
        #endregion

        #region # 生产计划映射 —— static ProductionPlanRp ToReportView(this ProductionPlanInfo...
        /// <summary>
        /// 生产计划映射
        /// </summary>
        public static ProductionPlanRp ToReportView(this ProductionPlanInfo productionPlanInfo)
        {
            ProductionPlanRp productionPlanRp = productionPlanInfo.Map<ProductionPlanInfo, ProductionPlanRp>();
            productionPlanRp.ProductionPlanNo = productionPlanInfo.Number;
            productionPlanRp.ProductName = productionPlanInfo.ProductInfo.Name;
            productionPlanRp.BomName = productionPlanInfo.BomInfo.Name;
            productionPlanRp.Unit = productionPlanInfo.ProductInfo.StandardUnitNo;

            return productionPlanRp;
        }
        #endregion

        #region # 作业计划映射 —— static ExecutionPlanRp ToReportView(this ExecutionPlanInfo...
        /// <summary>
        /// 作业计划映射
        /// </summary>
        public static ExecutionPlanRp ToReportView(this ExecutionPlanInfo productionPlanInfo)
        {
            ExecutionPlanRp productionPlanRp = productionPlanInfo.Map<ExecutionPlanInfo, ExecutionPlanRp>();
            productionPlanRp.ExecutionPlanNo = productionPlanInfo.Number;
            productionPlanRp.ProductName = productionPlanInfo.ProductInfo.Name;
            productionPlanRp.ProcessName = productionPlanInfo.ProcessInfo.Name;
            productionPlanRp.BomName = productionPlanInfo.BomInfo.Name;
            productionPlanRp.Unit = productionPlanInfo.ProductInfo.StandardUnitNo;

            return productionPlanRp;
        }
        #endregion

        #region # 工单映射 —— static WorkOrderRp ToReportView(this WorkOrderInfo...
        /// <summary>
        /// 工单映射
        /// </summary>
        public static WorkOrderRp ToReportView(this WorkOrderInfo workOrderInfo)
        {
            WorkOrderRp workOrderRp = workOrderInfo.Map<WorkOrderInfo, WorkOrderRp>();
            workOrderRp.DurationQuotaHours = workOrderInfo.DurationQuota.Hours;
            workOrderRp.ExecutionPlanName = workOrderInfo.ExecutionPlanInfo?.Name;
            workOrderRp.ProductionBatchNo = workOrderInfo.ExecutionPlanInfo?.ProductionBatchNo;
            workOrderRp.FacilityName = workOrderInfo.FacilityInfo?.Name;
            workOrderRp.WorkStationName = workOrderInfo.WorkStationInfo?.Name;
            workOrderRp.DispatchedTeamName = workOrderInfo.DispatchedTeamInfo?.Name;
            workOrderRp.DispatchedPersonName = workOrderInfo.DispatchedPersonInfo?.Name;

            return workOrderRp;
        }
        #endregion

        #region # 工序质检单映射 —— static WorkOrderInspectionRp ToReportView(this WorkOrderInspectionInfo...
        /// <summary>
        /// 工序质检单映射
        /// </summary>
        public static WorkOrderInspectionRp ToReportView(this WorkOrderInspectionInfo workOrderInspectionInfo)
        {
            WorkOrderInspectionRp workOrderInspectionRp = workOrderInspectionInfo.Map<WorkOrderInspectionInfo, WorkOrderInspectionRp>();
            workOrderInspectionRp.WorkOrderName = workOrderInspectionInfo.WorkOrderInfo?.Name;
            workOrderInspectionRp.WorkOrderNumber = workOrderInspectionInfo.WorkOrderInfo?.Number;
            workOrderInspectionRp.ProductionBatchNo = workOrderInspectionInfo.ExecutionPlanInfo?.ProductionBatchNo;
            workOrderInspectionRp.ExecutionPlanName = workOrderInspectionInfo.ExecutionPlanInfo?.Name;
            return workOrderInspectionRp;
        }
        #endregion

        #region # 成品质检单映射 —— static WorkOrderInspectionRp ToReportView(this WorkOrderInspectionInfo...
        /// <summary>
        /// 成品质检单映射
        /// </summary>
        public static ExecutionPlanInspectionRp ToReportView(this ExecutionPlanInspectionInfo executionPlanInspectionInfo)
        {
            ExecutionPlanInspectionRp executionPlanInspectionRp = executionPlanInspectionInfo.Map<ExecutionPlanInspectionInfo, ExecutionPlanInspectionRp>();
            executionPlanInspectionRp.ExecutionPlanName = executionPlanInspectionInfo.ExecutionPlanInfo?.Name;
            executionPlanInspectionRp.ExecutionPlanNumber = executionPlanInspectionInfo.ExecutionPlanInfo?.Number;
            executionPlanInspectionRp.ProductionBatchNo = executionPlanInspectionInfo.ExecutionPlanInfo?.ProductionBatchNo;
            executionPlanInspectionRp.ExecutionPlanName = executionPlanInspectionInfo.ExecutionPlanInfo?.Name;
            return executionPlanInspectionRp;
        }
        #endregion

        #region # 工序/成品质检明细映射 —— static QualityInspectionDetailDetailRp QualityInspectionDetailInfo...
        /// <summary>
        /// 工序/成品质检明细映射
        /// </summary>
        public static QualityInspectionDetailDetailRp ToReportView(this QualityInspectionDetailInfo detailInfo)
        {
            QualityInspectionDetailDetailRp detailRp = detailInfo.Map<QualityInspectionDetailInfo, QualityInspectionDetailDetailRp>();
            detailRp.ProductNumber = detailInfo.ProductInfo?.Number;
            detailRp.ProductName = detailInfo.ProductInfo?.Name;
            detailRp.StandardUnitNo = detailInfo.ProductInfo?.StandardUnitNo;
            return detailRp;
        }
        #endregion

        #region # 设备资产映射 —— static EquipmentAssetRp ToReportView(this EquipmentAssetInfo...
        /// <summary>
        /// 设备资产映射
        /// </summary>
        public static EquipmentAssetRp ToReportView(this EquipmentAssetInfo equipmentAssetInfo)
        {
            EquipmentAssetRp equipmentAssetRp = equipmentAssetInfo.Map<EquipmentAssetInfo, EquipmentAssetRp>();
            equipmentAssetRp.EquipmentNumber = equipmentAssetInfo.EquipmentInfo.Number;
            equipmentAssetRp.EquipmentName = equipmentAssetInfo.EquipmentInfo.Name;
            equipmentAssetRp.Status = equipmentAssetInfo.Status.GetEnumMember();

            return equipmentAssetRp;
        }
        #endregion

        #region # 设备维护记录映射 —— static EquipmentMaintenanceRp ToReportView(this EquipmentMaintenanceInfo...
        /// <summary>
        /// 设备维护记录映射
        /// </summary>
        public static EquipmentMaintenanceRp ToReportView(this EquipmentMaintenanceInfo equipmentMaintenanceInfo)
        {
            EquipmentMaintenanceRp equipmentMaintenanceRp = equipmentMaintenanceInfo.Map<EquipmentMaintenanceInfo, EquipmentMaintenanceRp>();
            equipmentMaintenanceRp.EquipmentMaintenanceNo = equipmentMaintenanceInfo.Number;
            equipmentMaintenanceRp.EquipmentMaintenanceName = equipmentMaintenanceInfo.Name;
            equipmentMaintenanceRp.FacilityName = equipmentMaintenanceInfo.FacilityInfo?.Name;

            return equipmentMaintenanceRp;
        }
        #endregion
    }
}
